//
//  MHMyReadVC.m
//  ManHua
//
//  Created by 江子安 on 15/10/27.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHMyReadVC.h"
#import "MHDataManager.h"
#import "MHReadListCell.h"
#import "MHComicDetailViewController.h"

@interface MHMyReadVC ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *ReadListArray;

@end

@implementation MHMyReadVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的阅读";
    self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:kThemeColor,UITextAttributeTextColor,nil];

    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    self.ReadListArray = [[MHDataManager shareManager]getReadList];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, Width, Height - 64) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"MHReadListCell" bundle:nil] forCellReuseIdentifier:@"readList"];
    CGFloat imageH = (Width / 4.0) / 9.0 * 11.0 + 20;
    if (130 > imageH) {
        self.tableView.rowHeight = 130;
    }
    else
    {
        self.tableView.rowHeight = imageH;
    }
    self.tableView.tableFooterView = [[UIView alloc]init];
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.ReadListArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MHReadListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"readList" forIndexPath:indexPath];
    cell.comicIntroduct = self.ReadListArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MHComicDetailViewController *comicDetailVC = [[MHComicDetailViewController alloc]init];
    comicDetailVC.comicIntroduct = self.ReadListArray[indexPath.row];
    [self.navigationController pushViewController:comicDetailVC animated:YES];
}

@end
